package dao;

import java.util.List;
import java.util.Vector;

import negocio.Insumo;

import org.hibernate.Session;
import org.hibernate.SessionFactory;

import dto.InsumoDTO;

public class ItemInsumoDAO {

	private static ItemInsumoDAO instancia = null;
	private static SessionFactory sf = null;
	
	public ItemInsumoDAO getInstancia ()
	{
		if(instancia == null)
			instancia = new ItemInsumoDAO();
		return instancia;
	}
	
	public void grabarInsumo (Insumo ins)
	{
		Session s = sf.openSession();
		s.beginTransaction();
		s.persist(ins);
		s.flush();
		s.getTransaction().commit();
		s.close();
	}
	
	public List<Insumo> obtenerInsumos ()
	{
		Session s=sf.openSession();
		List <Insumo> insumos = s.createQuery("from insumos").list();		
		return insumos;
	}
	
	public InsumoDTO obtenerInsumo(int numero)
	{
		Session s=sf.openSession();
		Insumo i = (Insumo) s.get(Insumo.class, numero);		
		return new InsumoDTO(i);
	}
}
